<?php
declare (strict_types = 1);
namespace app\common\middleware;

class Auth{
    /**
     * 处理请求
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)    {
        //获取请求的时候头部携带着这个token
        $token = $request->header('token');
        if ($request->isAjax() || $request->isPost())
        {
            if (empty($token))
            {
                return BackCode(null, 201, '请先登陆！');
            }
            else
            {
                $check = checkToken($token);
                if ($check['code'] == '201') {
                    return BackCode(null, 201, $check['msg']);
                }
            }
        }
        return $next($request);
    }
}